{extend name="index/public" /}

{block name="content"}
<form class="layui-form" action="" id="searchBox">
    <div class="layui-inline">
        <select name="channel_id" id="channel_id" lay-filter="channel_id" lay-search="">
            <option value="">渠道名称</option>
            {volist name="$channel_data" id="vo"}
            <option value="{$vo.cps_id}">{$vo.cps_id}：{$vo.cps_name}</option>
            {/volist}
        </select>
    </div>
    <div class="layui-inline" style="width: 800px;">
        <a href="javascript:;" class="layui-btn searchBtn my-btn my-btn-sm">搜索</a>
        <button class="layui-btn toolBtn my-btn my-btn-sm" type="button" id="oneSure">已处理</button>
        <button class="layui-btn toolBtn my-btn my-btn-sm" type="button" id="limitTime">限制申请时间</button>
        <button class="layui-btn toolBtn my-btn my-btn-sm" type="button" id="setNotice">设置公告</button>
    </div>
</form>

<table id="tableBox" lay-filter="tableBox"></table>

<script type="text/html" id="statusTpl">
    {{#  if(d.status === '已处理'){ }}
    <span class="layui-bg-green status1" val="{{ d.id }}" style="padding: 4px 6px;">{{ d.status }}</span>
    {{#  } else { }}
    <span class="layui-bg-red status2" val="{{ d.id }}" style="padding: 4px 6px;">{{ d.status }}</span>
    {{#  } }}

</script>

{/block}

{block name="css"}
<style>
</style>
{/block}

{block name="js"}
<script>
    layui.use(['table', 'laydate'], function(){
        var table = layui.table
            ,$ = layui.$
            ,form = layui.form
            ,load = null
            ,active = {
                reload: function () {
                    var channel_id = $('#channel_id').val();

                    table.reload('tableId', {
                        page: {curr: 1}
                        ,where: {channel_id:channel_id}
                        ,height: 'full-100'
                    })
                },
            };

        //表格初始化
        table.render({
            elem: '#tableBox'
            ,height: 'full-100'
            ,url: '{:url("AuditCpsApply/index")}'
            ,page: true
            ,limit:20
            ,limits:[20,40,60,80]
            ,loading:true
            ,id:'tableId'
            ,done: function (res, curr, count) {
                layer.close(load);
                $('#layui-loading').hide();
            }
            ,cols: [[
                {type:'checkbox', fixed: 'left'}
                ,{field:'cps_id', title: '渠道ID', width: 150, sort:true}
                ,{field:'cps_name', title: '渠道名称', width: 200}
                ,{field:'apply_time', title: '申请时间', width: 200, sort:true}
                ,{field:'status', title: '状态', width: 180, sort:true, templet: '#statusTpl'}
            ]]
        });

        $('#searchBox .searchBtn').on('click', function(){
            load = layer.load();
            active['reload'].call(this);
            return false;
        });

        //监听搜索栏
        $('#searchBox .toolBtn').on('click', function(){
            if($(this).attr('id')=='oneSure'){
                var checkStatus = table.checkStatus('tableId')
                    ,data = checkStatus.data
                    ,str = '';

                if(data.length==0){
                    layer.msg('请选择要修改的条目');
                    return false;
                }

                for(key in data){
                    str += data[key].id+',';
                }
                var load = layer.load();
                $.post('{:url("AuditCpsApply/oneSure")}',{all_id: str.substring(0, str.length-1)}, function(json){
                    layer.close(load);
                    if(json.code==0){
                        for (key in data){
                            $('.status2[val="'+data[key].id+'"]').text('已处理').addClass('layui-bg-green status1').removeClass('layui-bg-red status2');
                        }
                        layer.msg(json.msg, {icon: 1, time:1000})
                    }else{
                        layer.msg(json.msg, {icon: 0, time:1000});
                    }
                }, 'JSON').error(function(){
                    layer.close(load);
                    layer.msg('连接超时，请联系后台管理员', {icon: 2, time:3000});
                });
            }else if($(this).attr('id')=='limitTime'){
                layer.open({
                    type: 2
                    ,title: '限制申请时间'
                    ,area: ['100%', '100%']
                    ,content: '{:url("AuditCpsApply/limitTime")}'
                });
            }else if($(this).attr('id')=='setNotice'){
                layer.open({
                    type: 2
                    ,title: '设置公告'
                    ,area: ['100%', '100%']
                    ,content: '{:url("AuditCpsApply/setNotice")}'
                });
            }
        })
    });
</script>
{/block}